package com.hexinfo.dmpro.monitor.controller;

import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.common.base.Page;
import com.hexinfo.dmpro.monitor.model.base.MonitorReq;
import com.hexinfo.dmpro.common.annotation.Log;
import com.hexinfo.dmpro.monitor.model.base.MonitorReq;
import com.hexinfo.dmpro.monitor.model.cm.CmMessage;
import com.hexinfo.dmpro.monitor.model.cm.ResourceBaseReqModel;
import com.hexinfo.dmpro.monitor.model.cm.StateBaseReqModel;
import com.hexinfo.dmpro.monitor.service.MonitorSummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import javax.annotation.Resource;

/**
* @Auther:ht.zhou
* @Date:2024/01/04/16:23
* @Description:
*/

@RestController
@RequestMapping("/monitor_api/summary")
public class MonitorSummaryController {

    @Autowired
    private MonitorSummaryService monitorSummaryService;

    /**
     * 集群监控信息总览 服务状态数据测试
     * @param model
     * @return
     */
    @PostMapping(value = "/queryOverviewServiceRealTime")
    public ResponseEntity<Object> queryOverviewServiceRealTime(@RequestBody StateBaseReqModel model) {
        return new ResponseEntity<>(monitorSummaryService.queryOverviewServiceRealTime(model), HttpStatus.OK);
    }

    /**
     * 状态分组获取监控的所有集群服务状态
     * @return
     */
    @GetMapping(value = "/queryAllServiceCount")
    public ResponseEntity<Object> queryAllServiceCount(){
        return new ResponseEntity<>(monitorSummaryService.queryAllServiceCount(), HttpStatus.OK);
    }

    /**
     * 按照状态获取，监控集群这个状态所有服务信息
     * @param page
     * @param req
     * @return
     */
    @GetMapping(value = "/queryAllService")
    public ResponseEntity<Object> queryAllService(Page page, MonitorReq req){
        return new ResponseEntity<>(monitorSummaryService.queryAllService(page,req), HttpStatus.OK);
    }

    /**
     * 查询集群监控信息总览 资源利用率
     * @param model
     * @return
     */
    @Log("查询所有资源的利用率")
    @PostMapping("/selAllUtilization")
    public ResponseEntity<Object> selAllUtilization(@RequestBody ResourceBaseReqModel model) {
        List<Object> allUtilizationData = monitorSummaryService.selAllUtilization(model);
        return new ResponseEntity<>(allUtilizationData, HttpStatus.OK);
    }

    /**
     * 集群监控信息总览 作业数
     * @param commonReq
     * @return
     */
    @Log("查询 IMPALA 和 YARN 任务监控信息")
    @PostMapping("/selCombinedTaskCount")
    public ResponseEntity<Object> selCombinedTaskCount(@RequestBody MonitorReq commonReq) {
        return new ResponseEntity<>(monitorSummaryService.getCombinedTaskCount(commonReq), HttpStatus.OK);
    }

    /**
     * 监控总览，总资源、任务信息
     * @return
     */
    @GetMapping("/monitorStatusInquiry")
    public ResponseEntity<Object> monitorStatusInquiry()  {
        Object o = monitorSummaryService.monitorStatusInquiry();
        return new ResponseEntity(o,HttpStatus.OK);
    }

    @Log("首页统计信息点击列表")
    @GetMapping("/homePage")
    public ResponseEntity<Object> homePage(Page page, CmMessage cmMessage)  {
        Object o = monitorSummaryService.cmPageMessage(page,cmMessage);
        return new ResponseEntity(o,HttpStatus.OK);
    }

    @Log("主机详情")
    @GetMapping(value = "/queryAllHost")
    public ResponseEntity<Object> queryAllHost(Page page, MonitorReq req){
        return new ResponseEntity<>(monitorSummaryService.selectAllHost(page,req), HttpStatus.OK);
    }

    @Log("角色详情")
    @GetMapping(value = "/queryRoleStatePage")
    public ResponseEntity<Object> queryRoleStatePage(StateBaseReqModel model,Page page) {
        return new ResponseEntity<>(monitorSummaryService.queryRoleStatePage(model,page), HttpStatus.OK);
    }

    @Log("首页cpu使用率信息趋势图")
    @GetMapping("/cpuUsed")
    public ResponseEntity<Object> cpuUsed(String cmFlag,String clusterFlag,String startTime,String endTime)  {
        Object o = monitorSummaryService.cpuUsed(cmFlag,clusterFlag,startTime,endTime);
        return new ResponseEntity(o,HttpStatus.OK);
    }

    @Log("首页cpu分配率信息趋势图")
    @GetMapping("/cpuDistribution")
    public ResponseEntity<Object> cpuDistribution(String cmFlag,String clusterFlag,String startTime,String endTime)  {
        Object o = monitorSummaryService.cpuDistribution(cmFlag,clusterFlag,startTime,endTime);
        return new ResponseEntity(o,HttpStatus.OK);
    }

    @Log("首页内存使用率信息趋势图")
    @GetMapping("/memoryUsed")
    public ResponseEntity<Object> memoryUsed(String cmFlag,String clusterFlag,String startTime,String endTime)  {
        Object o = monitorSummaryService.memoryUsed(cmFlag,clusterFlag,startTime,endTime);
        return new ResponseEntity(o,HttpStatus.OK);
    }

    @Log("首页内存分配率信息趋势图")
    @GetMapping("/memoryDistribution")
    public ResponseEntity<Object> memoryDistribution(String cmFlag,String clusterFlag,String startTime,String endTime)  {
        Object o = monitorSummaryService.memoryDistribution(cmFlag,clusterFlag,startTime,endTime);
        return new ResponseEntity(o,HttpStatus.OK);
    }

    @Log("首页hdfs使用率")
    @GetMapping("/hdfsUsed")
    public ResponseEntity<Object> hdfsUsed(String cmFlag,String clusterFlag,String startTime,String endTime)  {
        Object o = monitorSummaryService.hdfsUsed(cmFlag,clusterFlag,startTime,endTime);
        return new ResponseEntity(o,HttpStatus.OK);
    }

    @Log("所有集群资源基础信息")
    @GetMapping("/cmResourceBasicData")
    public ResponseEntity<Object> cmResourceBasicData()  {
        Object o = monitorSummaryService.cmResourceBasicData();
        return new ResponseEntity(o,HttpStatus.OK);
    }
}
